1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.google.common.cache;
16
17
18
19
20
21
22 public class TestingWeighers {
23
24
25
26
27 static Weigher<Object, Object> constantWeigher(int constant) {
28 return new ConstantWeigher(constant);
29 }
30
31
32
33
34 static Weigher<Integer, Object> intKeyWeigher() {
35 return new IntKeyWeigher();
36 }
37
38
39
40
41 static Weigher<Object, Integer> intValueWeigher() {
42 return new IntValueWeigher();
43 }
44
45 static final class ConstantWeigher implements Weigher<Object, Object> {
46 private final int constant;
47
48 ConstantWeigher(int constant) {
49 this.constant = constant;
50 }
51
52 @Override
53 public int weigh(Object key, Object value) {
54 return constant;
55 }
56 }
57
58 static final class IntKeyWeigher implements Weigher<Integer, Object> {
59 @Override
60 public int weigh(Integer key, Object value) {
61 return key;
62 }
63 }
64
65 static final class IntValueWeigher implements Weigher<Object, Integer> {
66 @Override
67 public int weigh(Object key, Integer value) {
68 return value;
69 }
70 }
71
72 }